package com.dqhl.business.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dqhl.business.Base.BaseFragment;
import com.dqhl.business.R;
import com.dqhl.business.activity.CouponsActivity;
import com.dqhl.business.activity.LoginActivity;
import com.dqhl.business.activity.PromotionSettingActivity;
import com.dqhl.business.activity.ShopSettingActivity;
import com.dqhl.business.util.DeviceUtils;
import com.dqhl.business.util.UserSaveUtil;
import com.dqhl.business.view.CircleImageView;
import com.dqhl.business.view.WiperSwitch;

/**
 * Created by mac on 16/11/2.
 * OrderFragment
 */
public class PersonalFragment extends BaseFragment implements View.OnClickListener, WiperSwitch.OnChangedListener {

    private TextView tv_top_title;
    private CircleImageView iv_head;
    private TextView tv_order_amount; //订单数量
    private TextView tv_turnover; //营业额
    private TextView tv_version;//版本号
    private LinearLayout ll_shop_setting;
    private LinearLayout ll_coupon_setting;
    private LinearLayout ll_sale_setting;
    private LinearLayout ll_logout;
    private WiperSwitch switch_msg_push;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_personal, container, false);

        initView(view);
        initData();
        return view;
    }

    private void initData() {
        String version = DeviceUtils.getVersion(getActivity());
        tv_version.setText(version);
    }

    private void initView(View view) {
        tv_top_title = (TextView) view.findViewById(R.id.tv_top_title);
        iv_head = (CircleImageView) view.findViewById(R.id.iv_head);
        tv_order_amount = (TextView) view.findViewById(R.id.tv_order_amount);
        tv_turnover = (TextView) view.findViewById(R.id.tv_turnover);
        ll_shop_setting = (LinearLayout) view.findViewById(R.id.ll_shop_setting);
        ll_coupon_setting = (LinearLayout) view.findViewById(R.id.ll_coupon_setting);
        ll_sale_setting = (LinearLayout) view.findViewById(R.id.ll_sale_setting);
        ll_logout = (LinearLayout) view.findViewById(R.id.ll_logout);
        switch_msg_push = (WiperSwitch) view.findViewById(R.id.switch_msg);
        switch_msg_push.setChecked(true);
        (tv_version) = (TextView) view.findViewById(R.id.tv_version);

        tv_top_title.setText("个人");
        ll_shop_setting.setOnClickListener(this);
        ll_coupon_setting.setOnClickListener(this);
        ll_sale_setting.setOnClickListener(this);
        ll_logout.setOnClickListener(this);
        switch_msg_push.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //店铺设置
            case R.id.ll_shop_setting:
                overlay(ShopSettingActivity.class);
                break;
            case R.id.ll_coupon_setting:
                overlay(CouponsActivity.class);
                break;
            case R.id.ll_sale_setting:
                overlay(PromotionSettingActivity.class);
                break;
            case R.id.ll_logout:
                doLogout();
                break;
        }
    }

    private void doLogout() {
        UserSaveUtil.saveUser(getActivity(), null);
        forward(LoginActivity.class);
    }

    /**
     * 消息推送开关的监听事件
     *
     * @param wiperSwitch
     * @param checkState
     */
    @Override
    public void OnChanged(WiperSwitch wiperSwitch, boolean checkState) {

    }
}
